<?php
/**
 * Created by PhpStorm.
 * User: seven
 * Date: 14-12-10
 * Time: 下午3:11
 */
require 'global.php';

$gee=$sales_order=new DB(Tsales_order,$conn);
$sales_order_detail=new DB(Tsales_order_detail,$conn);

$ok = 0;
$order_id = isset($_GET['order_id']) ? $_GET['order_id'] : '';
$do = isset($_GET['do']) ? $_GET['do'] : '';
$reason_id = isset($_GET['reason_id']) ? $_GET['reason_id'] : '';
$reason_remark = isset($_GET['reason_remark']) ? $_GET['reason_remark'] : '';



if(empty($order_id) || empty($do)) exit;
//echo $do.'---'.$order_id;

$order = $gee->get_row($order_id, 'ref_no');
$code_refund_status = $code_array['refund_status'];
$code_order_status = $code_array['order_status'];
//print_r($order);
$data = array('ok' => 0);
if($order['order_status'] == 1){
    $refund_status = 0;
    $order_status = $order['order_status'];
    //echo $order['order_status'];
    $data = array('order_status' => '7');
    $res = $gee->update($data, 'ref_no', $order_id);
    $refund_status = 0;
    $order_cancel = array('sales_order_id' => $order_id, 'refund_reason_id' => $reason_id, 'customer_remark' => $reason_remark, 'refund_status' => $refund_status, 'order_status' => $order_status);
    $res1 = $refund->insert($order_cancel);
    $ok = 1;
    $data['ok'] = 1;
    //$data['order_status'] = 7;
    $data['order_id'] = $order_id;
    $data['code'] = $code_refund_status[$refund_status]['name_'.$lang];
}elseif($order['order_status'] == 2){
    $refund_status = 1;
    $order_status = $order['order_status'];
    $data = array('order_status' => '7');
    $res = $gee->update($data, 'ref_no', $order_id);
    $order_cancel = array('sales_order_id' => $order_id, 'refund_reason_id' => $reason_id, 'customer_remark' => $reason_remark, 'refund_status' => $refund_status, 'order_status' => $order_status);
    $res1 = $refund->insert($order_cancel);
    $ok = 1;
    $data['ok'] = 1;
    //$data['order_status'] = 7;
    $data['order_id'] = $order_id;
    $data['code'] = $code_order_status[7]['name_'.$lang].'，&nbsp;'.$code_refund_status[$refund_status]['name_'.$lang];

}elseif($order['order_status'] == 3){
    $refund_status = 1;
    $order_status = $order['order_status'];
    $data = array('order_status' => '7');
    $res = $gee->update($data, 'ref_no', $order_id);
    $order_cancel = array('sales_order_id' => $order_id, 'refund_reason_id' => $reason_id, 'customer_remark' => $reason_remark, 'refund_status' => $refund_status, 'order_status' => $order_status);
    $res1 = $refund->insert($order_cancel);
    $ok = 1;
    $data['ok'] = 1;
    //$data['order_status'] = 7;
    $data['order_id'] = $order_id;
    $data['code'] = $code_order_status[7]['name_'.$lang].'，&nbsp;'.$code_refund_status[$refund_status]['name_'.$lang];
}else{
    $ok = 0;
}
echo json_encode($data);
